﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DrSoftsFrame.Servers;

namespace PreeRegisterDAL
{
    public class OrderCompareDAL
    {
        /// <summary>
        /// 增加同煤版参数  liujia150812
        /// </summary>
        /// <param name="IFTmkyy"></param>
        /// <param name="strwhere"></param>
        /// <returns></returns>
        public static DataSet GetOrderCompareInfo(bool IFTmkyy,string strwhere)
        {
            try
            {
                string sqlstr = "";
                // 增加同煤版参数  liujia150812
                if (IFTmkyy)
                {
                    sqlstr = string.Format(@"--查询订单
                                                select iRegisterPreeNo=iPreRegister,cPreeCode=cPreRegisterCode
                                                ,cIdentityCard=cBookCode,bRegisteFlag=bImportFlag,iWorkPlanDetailId,dUpdate,cTel=cTelCode
                                                into #opdregisterpree 
                                                from HMPreRegister
                                                {0};", strwhere);
                }
                else
                {
                    sqlstr = string.Format(@"--查询订单
                                                select iRegisterPreeNo,cPreeCode,cIdentityCard,bRegisteFlag,iWorkPlanDetailId,dUpdate,cTel
                                                into #opdregisterpree 
                                                from opdregisterpree
                                                {0};", strwhere);
                }
                sqlstr += string.Format(@"
                                                --获取订单最大修改时间
                                                select top 1 dUpdate from #opdregisterpree
                                                order by dUpdate desc

                                                --获取订单
                                                select * from #opdregisterpree", strwhere);
                ClinicDb mydb = new ClinicDb();
                DataSet ds = mydb.ExecuteSelect(sqlstr);
                if (ds == null || ds.Tables.Count < 2)
                {
                    return null;
                }
                ds.Tables[0].TableName = "DtUpdate";
                ds.Tables[1].TableName = "opdregisterpree";
                return ds;

            }
            catch (Exception err)
            {

                throw;
            }
        }
    }
}
